package com.whmskj.xjlhbc.mobile;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;

public class GetStartDate {
    public static final String hour9 = " 09:00:00";
    private static final String hour15 = " 15:00:00";
    private static final String hour21 = " 21:00:00";
    public static final String day = "-21";

    //班次开始
    public static String getClassStartDate(){
        DateTime date = DateUtil.date();
        int dayOfWeek = date.dayOfWeek();//1表示周日，2表示周一
        int hour = date.hour(true);
        if(dayOfWeek == 1){
            if (hour > 9 && hour <= 15) {
                return DateUtil.today() + hour9;
            }
            if(hour > 15 && hour <= 21){
                return DateUtil.today() + hour15;
            }
        }else {
            if (hour > 9 && hour <= 21) {
                return DateUtil.today() + hour9;
            }
        }
        if(hour <= 9){
            return DateUtil.yesterday().toDateStr() + hour21;
        }
        return DateUtil.today() + hour21;
    }

    //日开始
    public static String getDayStartDate(){
        DateTime date = DateUtil.date();
        int hour = date.hour(true);
        if(hour < 9){
            return DateUtil.yesterday().toDateStr() + hour9;
        }
        return DateUtil.today() + hour9;
    }

    //昨日
    public static String getYesterdayStartDate(){
        return DateUtil.yesterday().toDateStr() + hour9;
    }

    //月
    public static String getMonthStartDate(){
        DateTime date = DateUtil.date();
        int dayOfMonth = date.dayOfMonth();
        if (dayOfMonth < 21) {
            DateTime dt = DateUtil.lastMonth().setField(DateField.DAY_OF_MONTH, 21);
            return dt.toDateStr() + hour9;
        }
        return date.setField(DateField.DAY_OF_MONTH, 21).toDateStr() + hour9;
    }

    //当前是几月
    public static int getMonthValue(){
        DateTime date = DateUtil.date();
        int dayOfMonth = date.dayOfMonth();
        if (dayOfMonth < 21) {
            return DateUtil.date().monthBaseOne();
        }
        return DateUtil.nextMonth().monthBaseOne();
    }
}
